﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization;

namespace UniRx
{
	// Token: 0x020001F7 RID: 503
	public sealed class DictionaryDisposable<TKey, TValue> : IDisposable, IDictionary<TKey, TValue>, IEnumerable, ICollection<KeyValuePair<TKey, TValue>>, IEnumerable<KeyValuePair<TKey, TValue>> where TValue : IDisposable
	{
		// Token: 0x06000A95 RID: 2709 RVA: 0x00038908 File Offset: 0x00036D08
		public DictionaryDisposable()
		{
			this.inner = new Dictionary<TKey, TValue>();
		}

		// Token: 0x06000A96 RID: 2710 RVA: 0x0003891B File Offset: 0x00036D1B
		public DictionaryDisposable(IEqualityComparer<TKey> comparer)
		{
			this.inner = new Dictionary<TKey, TValue>(comparer);
		}

		// Token: 0x170000D6 RID: 214
		public TValue this[TKey key]
		{
			get
			{
				object obj = this.inner;
				TValue result;
				lock (obj)
				{
					result = this.inner[key];
				}
				return result;
			}
			set
			{
				object obj = this.inner;
				lock (obj)
				{
					if (this.isDisposed)
					{
						value.Dispose();
					}
					TValue tvalue;
					if (this.TryGetValue(key, out tvalue))
					{
						tvalue.Dispose();
						this.inner[key] = value;
					}
					else
					{
						this.inner[key] = value;
					}
				}
			}
		}

		// Token: 0x170000D7 RID: 215
		// (get) Token: 0x06000A99 RID: 2713 RVA: 0x000389FC File Offset: 0x00036DFC
		public int Count
		{
			get
			{
				object obj = this.inner;
				int count;
				lock (obj)
				{
					count = this.inner.Count;
				}
				return count;
			}
		}

		// Token: 0x170000D8 RID: 216
		// (get) Token: 0x06000A9A RID: 2714 RVA: 0x00038A40 File Offset: 0x00036E40
		public Dictionary<TKey, TValue>.KeyCollection Keys
		{
			get
			{
				throw new NotSupportedException("please use .Select(x => x.Key).ToArray()");
			}
		}

		// Token: 0x170000D9 RID: 217
		// (get) Token: 0x06000A9B RID: 2715 RVA: 0x00038A4C File Offset: 0x00036E4C
		public Dictionary<TKey, TValue>.ValueCollection Values
		{
			get
			{
				throw new NotSupportedException("please use .Select(x => x.Value).ToArray()");
			}
		}

		// Token: 0x06000A9C RID: 2716 RVA: 0x00038A58 File Offset: 0x00036E58
		public void Add(TKey key, TValue value)
		{
			object obj = this.inner;
			lock (obj)
			{
				if (this.isDisposed)
				{
					value.Dispose();
				}
				else
				{
					this.inner.Add(key, value);
				}
			}
		}

		// Token: 0x06000A9D RID: 2717 RVA: 0x00038AB8 File Offset: 0x00036EB8
		public void Clear()
		{
			object obj = this.inner;
			lock (obj)
			{
				foreach (KeyValuePair<TKey, TValue> keyValuePair in this.inner)
				{
					TValue value = keyValuePair.Value;
					value.Dispose();
				}
				this.inner.Clear();
			}
		}

		// Token: 0x06000A9E RID: 2718 RVA: 0x00038B54 File Offset: 0x00036F54
		public bool Remove(TKey key)
		{
			object obj = this.inner;
			bool result;
			lock (obj)
			{
				TValue tvalue;
				if (this.inner.TryGetValue(key, out tvalue))
				{
					bool flag = this.inner.Remove(key);
					if (flag)
					{
						tvalue.Dispose();
					}
					result = flag;
				}
				else
				{
					result = false;
				}
			}
			return result;
		}

		// Token: 0x06000A9F RID: 2719 RVA: 0x00038BC8 File Offset: 0x00036FC8
		public bool ContainsKey(TKey key)
		{
			object obj = this.inner;
			bool result;
			lock (obj)
			{
				result = this.inner.ContainsKey(key);
			}
			return result;
		}

		// Token: 0x06000AA0 RID: 2720 RVA: 0x00038C0C File Offset: 0x0003700C
		public bool TryGetValue(TKey key, out TValue value)
		{
			object obj = this.inner;
			bool result;
			lock (obj)
			{
				result = this.inner.TryGetValue(key, out value);
			}
			return result;
		}

		// Token: 0x06000AA1 RID: 2721 RVA: 0x00038C54 File Offset: 0x00037054
		public Dictionary<TKey, TValue>.Enumerator GetEnumerator()
		{
			object obj = this.inner;
			Dictionary<TKey, TValue>.Enumerator enumerator;
			lock (obj)
			{
				enumerator = new Dictionary<TKey, TValue>(this.inner).GetEnumerator();
			}
			return enumerator;
		}

		// Token: 0x170000D3 RID: 211
		// (get) Token: 0x06000AA2 RID: 2722 RVA: 0x00038C9C File Offset: 0x0003709C
		bool ICollection<KeyValuePair<TKey, TValue>>.IsReadOnly
		{
			get
			{
				return ((ICollection<KeyValuePair<TKey, TValue>>)this.inner).IsReadOnly;
			}
		}

		// Token: 0x170000D4 RID: 212
		// (get) Token: 0x06000AA3 RID: 2723 RVA: 0x00038CAC File Offset: 0x000370AC
		ICollection<TKey> IDictionary<TKey, TValue>.Keys
		{
			get
			{
				object obj = this.inner;
				ICollection<TKey> result;
				lock (obj)
				{
					result = new List<TKey>(this.inner.Keys);
				}
				return result;
			}
		}

		// Token: 0x170000D5 RID: 213
		// (get) Token: 0x06000AA4 RID: 2724 RVA: 0x00038CF4 File Offset: 0x000370F4
		ICollection<TValue> IDictionary<TKey, TValue>.Values
		{
			get
			{
				object obj = this.inner;
				ICollection<TValue> result;
				lock (obj)
				{
					result = new List<TValue>(this.inner.Values);
				}
				return result;
			}
		}

		// Token: 0x06000AA5 RID: 2725 RVA: 0x00038D3C File Offset: 0x0003713C
		public void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			object obj = this.inner;
			lock (obj)
			{
				((ISerializable)this.inner).GetObjectData(info, context);
			}
		}

		// Token: 0x06000AA6 RID: 2726 RVA: 0x00038D80 File Offset: 0x00037180
		public void OnDeserialization(object sender)
		{
			object obj = this.inner;
			lock (obj)
			{
				((IDeserializationCallback)this.inner).OnDeserialization(sender);
			}
		}

		// Token: 0x06000AA7 RID: 2727 RVA: 0x00038DC4 File Offset: 0x000371C4
		void ICollection<KeyValuePair<TKey, TValue>>.Add(KeyValuePair<TKey, TValue> item)
		{
			this.Add(item.Key, item.Value);
		}

		// Token: 0x06000AA8 RID: 2728 RVA: 0x00038DDC File Offset: 0x000371DC
		bool ICollection<KeyValuePair<TKey, TValue>>.Contains(KeyValuePair<TKey, TValue> item)
		{
			object obj = this.inner;
			bool result;
			lock (obj)
			{
				result = ((ICollection<KeyValuePair<TKey, TValue>>)this.inner).Contains(item);
			}
			return result;
		}

		// Token: 0x06000AA9 RID: 2729 RVA: 0x00038E20 File Offset: 0x00037220
		void ICollection<KeyValuePair<TKey, TValue>>.CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex)
		{
			object obj = this.inner;
			lock (obj)
			{
				((ICollection<KeyValuePair<TKey, TValue>>)this.inner).CopyTo(array, arrayIndex);
			}
		}

		// Token: 0x06000AAA RID: 2730 RVA: 0x00038E64 File Offset: 0x00037264
		IEnumerator<KeyValuePair<TKey, TValue>> IEnumerable<KeyValuePair<TKey, TValue>>.GetEnumerator()
		{
			object obj = this.inner;
			IEnumerator<KeyValuePair<TKey, TValue>> result;
			lock (obj)
			{
				result = new List<KeyValuePair<TKey, TValue>>(this.inner).GetEnumerator();
			}
			return result;
		}

		// Token: 0x06000AAB RID: 2731 RVA: 0x00038EB4 File Offset: 0x000372B4
		IEnumerator IEnumerable.GetEnumerator()
		{
			return this.GetEnumerator();
		}

		// Token: 0x06000AAC RID: 2732 RVA: 0x00038EC1 File Offset: 0x000372C1
		bool ICollection<KeyValuePair<TKey, TValue>>.Remove(KeyValuePair<TKey, TValue> item)
		{
			throw new NotSupportedException();
		}

		// Token: 0x06000AAD RID: 2733 RVA: 0x00038EC8 File Offset: 0x000372C8
		public void Dispose()
		{
			object obj = this.inner;
			lock (obj)
			{
				if (!this.isDisposed)
				{
					this.isDisposed = true;
					foreach (KeyValuePair<TKey, TValue> keyValuePair in this.inner)
					{
						TValue value = keyValuePair.Value;
						value.Dispose();
					}
					this.inner.Clear();
				}
			}
		}

		// Token: 0x040006E8 RID: 1768
		private bool isDisposed;

		// Token: 0x040006E9 RID: 1769
		private readonly Dictionary<TKey, TValue> inner;
	}
}
